/*
* @Author: chenggh
* @Date: 2025-06-20
* @Link to Problem : https://webvpn.neu.edu.cn/https/62304135386136393339346365373340bfebea318fd008d8f60d257088/courses/27/part/222/problem/1005
*/
#include <iostream>
#include <set>
using namespace std;
// 数据流找中位数
class MedianFinder{
private:
	// 维护小的一部分，我需要较大顶堆
	multiset<int> lower_set, upper_set;
	void update(){
		// 调整 upper >= lower
		if(lower_set.size() > upper_set.size()){
			auto it = lower_set.begin();
			int temp = -*it;
			lower_set.erase(it);
			upper_set.insert(temp);
			return;
		}
		if(lower_set.size() + 1 < upper_set.size()){
			auto it = upper_set.begin();
			int temp = -*it;
			upper_set.erase(it);
			lower_set.insert(temp);
			return;
		}
	}
public:
	MedianFinder(){}
	void insert(int num){
		// 插入 这里插入逻辑有问题
		// 这里应该往尽可能多的地方插入
		// 像下面这种就会导致可能需要swap来更新 所以错到底！！！
		if(lower_set.empty() || num <= -(*lower_set.begin())){
			lower_set.insert(-num); // 放入大顶堆 (较小的一半)
		}else upper_set.insert(num);  // 放入小顶堆 (较大的一半)
		show();
		update();
		return;
	}
	void pop(int num){
		if(num <= -*lower_set.begin()){
			auto it = lower_set.find(-num);
			lower_set.erase(it);
			update();
			return;
		}
		auto it = upper_set.find(num);
		upper_set.erase(it);
		update();
		return;
	}
	int get_median(){
		if(lower_set.size() == upper_set.size()){
			// 有可能越界
			return (-*lower_set.begin());
		}
		return (*upper_set.begin());
	}
	void show(){
		for(auto x: lower_set){
			cout << -x << " ";
		}cout << endl;
		for(auto x: upper_set){
			cout << x << " ";
		}cout << endl;
		cout << "11111111111" << endl;
	}
};
#include <vector>
int main(){
	int n, k; cin >> n >> k;
	MedianFinder finder;
	vector<int> v;
	for(int i = 0, temp; i < n; i++){
		cin >> temp;
		v.push_back(temp);
		finder.insert(temp);
		// finder.show();
		// 处理完第k - 1个就输出
		// 左指针i - k + 1, 右指针 i []
		if(i > k - 1) cout << " " ;
		if(i >= k - 1){
			cout << finder.get_median();
			finder.pop(v[i - k + 1]);
		}
	}cout << endl;
	return 0;
}